﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using eTerm.MsSql.DbProvider;
using System.Web.Security;
using eTerm.Platform.Common;

namespace eTerm.Platform.Web
{
    public partial class Login : BasePage
    {

        protected override void InitEasyUI()
        {
            BaseRegisterStartupScript<Page>(this, btLogin.ClientID, string.Format(@"$('#{0}').linkbutton({{   
    iconCls: 'icon-search'  
}});  
", btLogin.ClientID), true);

        }

        protected void btLogin_Click(object sender, EventArgs e)
        {
            string returnUrl = Request.QueryString["ReturnUrl"];
            string password = Encrypt.MD5Encrypt(txtPass.Text.Trim());
            SysUser model = SysUser.FirstOrDefault(l => l.CompanyCode == txtCompany.Text.Trim() && l.UserNo == txtName.Text.Trim() && l.Password == password);
            if (model == null) return;
            FormsAuthentication.SetAuthCookie(model.UserId.ToString(), false);
            Response.Redirect(string.IsNullOrEmpty(returnUrl) ? @"~/Default.aspx" : returnUrl);
        }
    }
}
